<template>
  <a-form :model="formData" :rules="rules" ref="form" class="modify-relation-ship">
    <a-form-item label="与户主关系" name="relation">
      <a-radio-group v-model:value="formData.relation" :options="dataList" />
    </a-form-item>
    <a-form-item label="到期时间" name="rent_deadline" v-if="formData.relation == 'D0006_4'">
      <a-date-picker v-model:value="formData.rent_deadline" value-format="YYYY-MM-DD" />
    </a-form-item>
  </a-form>
</template>

<script>
import get from 'lodash-es/get.js';
import { updateRelation } from '@gis/lib/api/index.js';
import { handleFormRes } from '@gis/lib/utils/resolver.js';
import { useDicDataStore } from '@gis/lib/pinia/dicData.js';

export default {
  name: 'modify-relation-ship',
  components: {},
  props: {
    data: { type: Object, default: () => ({}) },
  },
  data() {
    return {
      rules: {
        relation: { required: true, message: '请选择与户主关系' },
        rent_deadline: { required: true, message: '请选择租约到期时间' },
      },
      formData: {
        relation: get(this.data, 'relation'),
      },
      type: 'D0006',
    };
  },
  computed: {
    dataList() {
      return this.dicData.getDicDataList(this.type);
    },
  },
  mounted() {
    this.dicData.getDicDataAsync(this.type);
  },
  methods: {
    async onOk() {
      const valid = await this.$refs.form.validate();
      if (!valid) return;
      const params = Object.assign({}, this.formData, {
        link_id: this.data.link_id,
      });
      return await handleFormRes(updateRelation(params));
    },
  },
  setup() {
    const dicData = useDicDataStore();
    return { dicData };
  },
};
</script>

<style scoped lang="less">
.modify-relation-ship {
  padding: 24px;
}
</style>
